package testjson;


import com.alibaba.fastjson.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.sql.*;
import java.util.Random;

public class BaseDao {
    protected static final Log log = LogFactory.getLog(BaseDao.class);
    private static String driver="org.apache.phoenix.jdbc.PhoenixDriver";
    private static String url = "jdbc:phoenix:192.168.0.6:2181/hbase";
    Connection conn = null;
    PreparedStatement pstmt = null;

    public BaseDao(){

        try {
            conn = getconnect();
            log.info("conncet is connect");
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }


   static  {
       try {
           Class.forName(driver);

       } catch (ClassNotFoundException e) {
           System.out.println("org.apache.phoenix.jdbc.PhoenixDriver未找到");
       }


   }

private int count=0;

    public static Connection getconnect() throws SQLException {

            return  DriverManager.getConnection(url);

    }


    public static void closeAll(Connection conn, Statement stmt, ResultSet rs) throws SQLException {
        if(rs!=null) {
            rs.close();
        }
        if(stmt!=null) {
            stmt.close();
        }
        if(conn!=null) {
            conn.close();
        }
    }



    /***
     * This method returns String rowkey
     * @param str The value to be rowkeys
     * @return rowkey string
     */
    public String rowkeys(String str) {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < str.length(); i++) {
            buffer.append(str.charAt(new Random().nextInt(str.length())));

        }

        return buffer.toString();


    }


}
